/*
 * @Author: yuqy
 * @Date: 2023-04-11 13:47:20
 * @LastEditors: yuqy
 * @LastEditTime: 2023-10-19 14:21:17
 * @Descripttion: -
 */
import { createStore } from 'vuex'
import user from './modules/user'
import roomAgora from './modules/roomAgora'
export default createStore({
  state: {
    info: 'hello',
    isLoading: false,
    isLoadMessageing: false,
    nowSystem: 'web', // 当前运行系统 默认是web
    APP_NAME: '',
    APP_VERSON: '',
    APP_WEB_SOCKET_URL: 'wss://whiteboard.njodin.com/whiteboardsocket/webSocket/'
  },
  mutations: {
    // 定义mutations，用于修改状态(同步)
    updateInfo (state, payload) {
      state.info = payload
    },
    updateLoading(state, bool) { // 第一个参数是vuex固定的参数，不需要手动去传递
      state.isLoading = bool; 
    },
    updateMessageLoading(state, bool) {
      state.isLoadMessageing = bool; 
    },
    // 更新app信息
    updateSystem(state, { nowSystem, name, version }) {
      if (nowSystem && nowSystem != 'underfined') {
        state.nowSystem = nowSystem; 
      }
      state.APP_NAME = name; 
      state.APP_VERSON = version; 
    },
  },
  actions: {
    // 定义actions，用于修改状态(异步)
    // 2秒后更新状态
    updateInfo (context, payload) {
      setTimeout(() => {
        context.commit('updateInfo', payload)
      }, 2000)
    },
    updateLoadingFn(context, bool) {
      context.commit('updateLoading', bool)
    },
    updateMessageLoadingFn(context, bool) {
      context.commit('updateMessageLoading', bool)
    },
  },
  getters: {
    // 定义一个getters
    formatInfo (state) {
      return state.info + ' Tom'
    },
    getLoading: (state) => {
      return state.isLoading
    },
    getMessaegLoading: (state) => {
      return state.isLoadMessageing
    },
    getAppIsWeb (state) {
      return state.nowSystem == 'web';
    }
  },
  modules: {
    user,
    roomAgora
  }
})